@extends("backend.layout.main")



@section("right_content")
    <!--middle-->
    <div class="mainWrapBox">
        <div class="mainBox">
			
	<h1>项目阶段设置</h1>
	<div class="html">
		<div class="w220 f_l">
			@include('backend.layout.comset')

		</div>
		<div class="auto-width-220">
			<div class="listWrapbox mt10" id="main-right">
			<h2>参数设置</h2>
                <div class="inbox-one">
					<div class="inbox-nav"><span>项目阶段</span></div>
					<div class="inbox-input">
						<input placeholder="输入项目阶段,按回车提交" class="set-input addProjectSet" maxlength="30" type="text" id="">
					</div>

					<style>
						.btn1{background: url(../images/icon_remove2.png) no-repeat;margin-top:20px;}
					</style>
					@foreach( $stages as $f )
					      
                    <div onmouseout="hide_tag(this);" onmousemove="remove_tag(this);">
						<div class="inbox-list" style="padding: 0px;height: 35px;line-height: 35px;">{{ $f->name }}</div>
                        <input type="button" class="btn1" data="{{ $f->sid }}" style="display: none" id="3">
					</div>
                    @endforeach	      	                          	
                            	
				</div>	
			</div>
		</div>
	</div>
 <script type="text/javascript">
		/* * 隐藏删除按钮
		 * @param obj
		 */
		function hide_tag(obj){

			$(obj).find("input[type='button']").hide();

		}

		/**
		 * 显示删除按钮
		 * @param obj
		 */
		function remove_tag(obj){
           
            $(obj).find("input[type='button']").show();
		}

    </script>

    <script type="text/javascript">
        $(function () {
			$(document).on('click','.btn1',function(){
				
                    var that = $(this);
					
					var t = confirm('确认删除此记录？');
					
					if(t){
						
						if(t){
							$.post('/backend/program/' + that.attr("data"), {'_method': 'delete'}, function(d){
								if(d == 1){
									  
									that.prev().remove();
									
								}else{
									alert("删除失败");
								}
							})
						}
					}
			})
		});

       $(document).on('keypress','.addProjectSet',function(e){			  
            
            var e=e || event;
            keycode=e.which || e.keyCode;
			//当按下enter健时，保存。
            if(keycode==13){
			    saveSetting(this);
            }
        });

        function check(obj){
            var txt = $.trim($(obj).val());
			var type = $(obj).parent().prev().find("span").text();
			var isNotNullOrRepeat = true;
			if(txt==''){g
				alert(type+"必填");
                isNotNullOrRepeat = false;
			}else if(txt.length>30){
				alert("长度不能超过30个字符");
                isNotNullOrRepeat = false;
			}else{
				$(obj).parent().parent().find(".inbox-list").each(function(){
					var inbox = $(this).text();
					if(inbox == txt){
						alert(type+"不能重复");
                        isNotNullOrRepeat = false;
						return;
					}
				});
			}

            return isNotNullOrRepeat;
        }

        function saveSetting(obj){

            if(check(obj)){

				var inbox = $.trim($(obj).val());
                var id = $(obj).attr('id');
       
				$.ajax({
					
					url : "/backend/program",
					type : "post",
					data : {
						'name':inbox,
						'orgId': id
					},
					success : function(e) {

						var html="<div onmouseout='hide_tag(this);' onmousemove='remove_tag(this);'><div class='inbox-list'style='padding: 0px;height: 35px;line-height: 35px;'>"+inbox+"</div><input type='button' class='btn1'data='999' style='display: none'></div>";
					
						$(".inbox-one").append(html);
					
					}
					
				});
			}
		}
       	
</script>
  
        </div>
    </div>
</div>
</div>
@endsection
